<template>
  <div class="register-area" data-info="自动结算">
    <el-button class="next" @click="handleNext" type="primary">
      下一步{{ stepInfo }}
    </el-button>

    <div class="step-comps-area" data-info="具体的业务">
      <component
        :is="curCompName"
        @handleSure="handleSure"
        @handlePatientInfoSure="handlePatientInfoSure"
      />
    </div>
    <!--底部操作-->
    <PatientNumberOperate   :key="widget" @handleBack="handlePre" :time="120000" />
  </div>
</template>

<script>
import CardType from "@sc/DRCbiz/comps/cardType/index.vue";
import MedInsCode from "@sc/DRCbiz/comps/medInsCode/index.vue";
import PatientInfo from "@sc/DRCbiz/comps/patientInfo/index.vue";
import AutoStlmtResult from "@sc/DRCbiz/comps/autoStlmtResult/index.vue";
import PatientNumberOperate from "@sc/DRCbiz/comps/patientNumberOperate/index.vue";
import PaymentAndSettlement from "@sc/DRCbiz/comps/Payment-and-settlement/index.vue";
import SelectPaymentMethod from "@sc/DRCbiz/comps/Select-payment-method/index.vue";
import PaymentReminder from "@sc/DRCbiz/comps/Payment-reminder/index.vue";
import PaymentSuccess from "@sc/DRCbiz/comps/Payment-success/index.vue";
import { v4 as uuid } from "uuid";
import CostInquiryPlatform from "@sc/DRCbiz/comps/Cost-inquiry-platform/index.vue";

import { AndroidToWeb, buildParentApi } from "@/utils/designer/util";
let buildParent = buildParentApi();
export default {
  name: "ExpInq",

  componentName: "ExpInq",

  components: {
    CostInquiryPlatform,
    CardType,
    MedInsCode,
    PatientInfo,
    AutoStlmtResult,
    PatientNumberOperate,
    PaymentAndSettlement,
    SelectPaymentMethod,
    PaymentReminder,
    PaymentSuccess,
  },

  data() {
    return {
        widget: uuid(),
      steps: 1,
      curCompName: "CardType",
      compsOptions: {
        1: "CostInquiryPlatform",
        2: "CardType",
        3: "MedInsCode",
        4: "PatientInfo",
        5: "AutoStlmtResult",
        6: "PaymentAndSettlement",
        7: "SelectPaymentMethod",
        8: "PaymentReminder",
        9: "PaymentSuccess",
      },
    };
  },

  computed: {
    shownOperate() {
      return this.steps !== 1;
    },
    patientInfo() {
      return this.$store.getters["DRCbiz/getPatientInfo"];
    },
    // 步骤
    stepInfo() {
      return this.$store.getters["DRCbiz/getStepsInfo"];
    },
    //选中的卡片信息
    cardTypeInfo() {
      return this.$store.getters['DRCbiz/getCardTypeInfo']
    },
  },

  mounted() {
    this.$store.dispatch("DRCbiz/setCTDTimeInfo", 1200000);
  },

  methods: {
    // 患者信息-->获取门诊类型
    handlePatientInfoSure() {
      console.log(11111)
      // let stepInfo = parseInt(this.stepInfo);
      // this.$store.dispatch("DRCbiz/setStepsInfo", ++stepInfo);
      console.log("sure1", useMsg, this.patientInfo);
      // 明细
      //        <Request>
      //   <deviceIp>172.17.43.202</deviceIp>
      //   <flowId>JWS30320250206081221928</flowId>
      //   <timestamp>20250206081221928</timestamp>
      //   <terminalNo>JWS303</terminalNo>
      //   <method>QueryCostDetail</method>
      //   <patientId>4026835</patientId>
      //   <billNo>032920066,032920067,032920068,032920069,032920070,032920071</billNo>
      // </Request>
      // 概要
      // <Request>
      //   <deviceIp>172.17.43.202</deviceIp>
      //   <flowId>JWS30320250206081219385</flowId>
      //   <timestamp>20250206081219385</timestamp>
      //   <terminalNo>JWS303</terminalNo>
      //   <method>QueryCostSummary</method>
      //   <patientId>4026835</patientId>
      // </Request>
      const { patientId } = this.patientInfo;
      let params = {
        Request: {
          deviceIp: "",
          flowId: "",
          timestamp: "",
          terminalNo: "",
          method: "QueryCostDetail",
          patientId, // 医院病人id	C	不可空	根据医院要求确定是否可空
        },
      };
      let paramsInfo = this.$x2js.js2xml(params);
      buildParent.executeParentMethod(
        "axiosRep",
        paramsInfo,
        "QueryCostDetail"
      );
      // 出参
      // "RecordInfo": [
      //   {
      //     "billNo": "18059239",
      //     "billDate": "2025/2/6 16:37:00",
      //     "billType": "西药",
      //     "deptCode": "261",
      //     "deptName": "妇科综合门诊",
      //     "doctCode": "8628",
      //     "doctName": "於莉英",
      //     "productCode": "512947",
      //     "itemName": "D葡萄糖注射液",
      //     "itemSpecs": "20ml:10g(50%)",
      //     "itemLiquid": "注射液",
      //     "itemUnits": "瓶",
      //     "itemQty": "8",
      //     "itemPrice": "113",
      //     "billFee": "904",
      //     "itemNo": "7101464",
      //     "hosFeeNo": "512947",
      //     "diseasetype": "0"
      //   },
      //   {
      //     "billNo": "032931685",
      //     "billDate": "2025/2/6 16:36:54",
      //     "billType": "检查",
      //     "deptCode": "261",
      //     "deptName": "妇科综合门诊",
      //     "doctCode": "8628",
      //     "doctName": "於莉英",
      //     "productCode": "87",
      //     "itemName": "静脉采血",
      //     "itemUnits": "次",
      //     "itemQty": "1",
      //     "itemPrice": "580",
      //     "billFee": "580",
      //     "itemNo": "42430725",
      //     "hosFeeNo": "87",
      //     "diseasetype": "0"
      //   },
      // ]
    },
    handleSure(useMsg) {
      
    },
    async handleNext() {
       let stepInfo = parseInt(this.stepInfo);
      this.widget = uuid();
      if (stepInfo === 8) {
        await this.$store.dispatch("DRCbiz/setStepsInfo", 1);
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", ++stepInfo);
      }
    },

    // 返回上一层&首页
    async handlePre() {
      this.widget = uuid();
      let stepInfo = parseInt(this.stepInfo);
      if (stepInfo === 1) {
        await this.$router.push({
          path: `/DRCbizList`,
        });
      } else {
        await this.$store.dispatch("DRCbiz/setStepsInfo", --stepInfo);
      }
      switch (parseInt(this.stepInfo)) {
        case 2:
          let cardTypeInfo = this.cardTypeInfo;
          Reflect.set(cardTypeInfo, "cardNo", null);
          await this.$store.dispatch("DRCbiz/setCardTypeInfo", cardTypeInfo);
          buildParent.executeParentMethod("openScan");
          break;
      }
    },
  },

  watch: {
     // 步距
    stepInfo: {
      handler: function (val) {
        const self = this;
        self.widget = uuid();
        let cardTypeInfo = self.cardTypeInfo;
        if ( cardTypeInfo && val === 2) {
          // 电子医保特殊处理
          if (parseInt(cardTypeInfo?.id) === 29) {
            buildParent.executeParentMethod("MICode");
          } else {
            buildParent.executeParentMethod("openScan");
          }
        } else {
          buildParent.executeParentMethod("closeScan");
        }
        
        self.curCompName = Reflect.get(self.compsOptions, val);

      },
      deep: true,
      immediate: true,
    },
  },
};
</script>

<style scoped lang="scss">
@import "./assets/style";
</style>